package com.koron.configure.shiftTip.controller;


import com.koron.bean.base.Response;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.configure.shiftTip.bean.po.ConfigureShiftTip;
import com.koron.configure.shiftTip.service.ConfigureShiftTipService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.List;

/**
 * 交接事项(ConfigureShiftTip)表控制层
 *
 * @author jzp
 * @since 2022-03-21 18:13:30
 */
@Api(tags = "交接事项接口")
@RestController
@RequestMapping("tip")
public class ConfigureShiftTipController {
    /**
     * 服务对象
     */
    @Autowired
    private ConfigureShiftTipService configureShiftTipService;

    private String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation(value = "根据id查询")
    @GetMapping
    public Response<ConfigureShiftTip> selectOne(@RequestParam String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), configureShiftTipService, "getById", ConfigureShiftTip.class, id));
    }

    @ApiOperation(value = "查询所有", notes = "根据dockingId查询")
    @GetMapping("list")
    public Response<List<ConfigureShiftTip>> list(String dockingId) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), configureShiftTipService, "listByDockingId", List.class, dockingId));
    }

    @ApiOperation(value = "新增或修改")
    @PostMapping("add")
    public Response<String> add(@RequestBody ConfigureShiftTip configureShiftTip) {
        ADOConnection.runTask(getCurrDs(), configureShiftTipService, "save", Boolean.class, configureShiftTip);
        return Response.ok(configureShiftTip.getId());
    }

    @ApiOperation(value = "插入")
    @PostMapping("insert")
    public Response<String> insert(@RequestBody ConfigureShiftTip configureShiftTip) {
        ADOConnection.runTask(getCurrDs(), configureShiftTipService, "insert", Boolean.class, configureShiftTip);
        return Response.ok(configureShiftTip.getId());
    }

    @ApiOperation(value = "删除")
    @DeleteMapping
    public Response<Boolean> delete(@RequestParam String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), configureShiftTipService, "deleteBatchIds", Boolean.class, Collections.singletonList(id)));
    }


    @ApiOperation(value = "根据DockingId删除")
    @DeleteMapping("docking")
    public Response<Boolean> deleteByDockingId(String dockingId) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), configureShiftTipService, "removeByDockingId", Boolean.class, dockingId));
    }

}
